<?php 
class GetTags_model extends Model{
	function GetTags_model()
	{
		parent::Model();
	    //$this->load->database();
       // $this->load->model('test');
	}
/*	function get_ptags()
	{
		//$this->db->select('name');
		$query1=$this->db->get('ci_ask_pcat');	
		return $query1->result();		
	}
	function get_ctags()
	{	
	    //$query="select ci_ask_ccat.name from ci_ask_pcat left join ci_ask_ccat on ci_ask_ccat.pid = ci_ask_pcat.id";
	    //$query2=$this->db->query($query);
    	//$this->db->select('name');
		$query2=$this->db->get('ci_ask_ccat');	
	    return $query2->result();	
	}*/
	
	function getAllCategorys($asArray = false,$params = array() )
	{
		$this->db->select('ci_ask_ccat.id as cid ,
		                   ci_ask_ccat.name as cname,
						   ci_ask_pcat.id as pid,
						   ci_ask_pcat.name as pname');
  		$this->db->join('ci_ask_pcat','ci_ask_ccat.pid = ci_ask_pcat.id');
  		$this->db->order_by('ci_ask_pcat.id asc');
  		$query = $this->db->get('ci_ask_ccat');
  		$query2 = $query->result_array();
  		if($asArray)
  		{
  			$tempPname = '';
  			foreach($query2 as $item)
  			{
  				if($tempPname != $item['pname'] )
  				{
  					$list[] = array('pid' => $item['pid'], 'pname' => $item['pname'] );
  				}
  				$tempPname = $item['pname'];
  			}
  			foreach($list as $item)
  			{
  				foreach($query2 as $childItem)
  				{
  					if($childItem['pid'] == $item['pid'])
  					   $item['child'][] = array('cid' => $childItem['cid'],'cname' => $childItem['cname']);				    
  				}
  				$relist[] = $item;
  			}  			
  			return $relist;
  		}
  		
	}
	
}
 ?>